package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:NursingLevelController
 * package:com.zzyl.controller
 * description:
 *
 * @author 刘
 * @version 1.0
 * @Create 2024/6/2 10:22
 */
@Api(tags = "护理等级")
@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> getAllLevel(){
        List<NursingLevelVo> list = nursingLevelService.getAllLevel();
        return ResponseResult.success(list);
    }

    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult insertLevel(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.insertLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    @ApiOperation("条件分页查询")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> selectByLimit(@RequestParam Integer pageNum,
                                        @RequestParam Integer pageSize,
                                        @RequestParam(required = false) String name,
                                        @RequestParam(required = false) Integer status){
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.selectByLimit(pageNum,pageSize,name,status);
        return ResponseResult.success(pageResponse);
    }

    @ApiOperation("根据id查询护理等级")
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Integer id){
        NursingLevelVo nursingLevelVo = nursingLevelService.selectById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    @ApiOperation("修改")
    @PutMapping("/update")
    public ResponseResult updateLevel(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.updateLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteLevelById(@PathVariable Integer id){
        nursingLevelService.deleteLevel(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatusById(@PathVariable Integer id,
                                           @PathVariable Integer status){
        nursingLevelService.updateStatusById(id,status);
        return ResponseResult.success();
    }
}
